// Copyright (C) Kumo inc. and its affiliates.
// Author: Jeff.li lijippy@163.com
// All rights reserved.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.
//
#pragma once

namespace kumo::pollux::exec {
    struct VectorFunctionMetadata {
        /// Boolean indicating whether this function supports flattening, i.e.
        /// converting a set of nested calls into a single call.
        ///
        ///     f(a, f(b, f(c, d))) => f(a, b, c, d).
        ///
        /// For example, concat(string,...), concat(array,...), map_concat(map,...)
        /// Presto functions support flattening. Similarly, built-in special format
        /// AND and OR also support flattening.
        ///
        /// A function that supports flattening must have a signature with variadic
        /// arguments of the same type. The result type must be the same as input
        /// type.
        bool supportsFlattening{false};

        /// True if the function is deterministic, e.g given same inputs always
        /// returns same result.
        bool deterministic{true};

        /// True if null in any argument always produces null result.
        /// In this case, 'rows' in VectorFunction::apply will point only to positions
        /// for which all arguments are not null.
        bool defaultNullBehavior{true};

        /// Indicates if this is a companion function.
        bool companionFunction{false};
    };

    class VectorFunctionMetadataBuilder {
    public:
        VectorFunctionMetadataBuilder &supportsFlattening(bool supportsFlattening) {
            metadata_.supportsFlattening = supportsFlattening;
            return *this;
        }

        VectorFunctionMetadataBuilder &deterministic(bool deterministic) {
            metadata_.deterministic = deterministic;
            return *this;
        }

        VectorFunctionMetadataBuilder &defaultNullBehavior(bool defaultNullBehavior) {
            metadata_.defaultNullBehavior = defaultNullBehavior;
            return *this;
        }

        VectorFunctionMetadataBuilder &companionFunction(bool companionFunction) {
            metadata_.companionFunction = companionFunction;
            return *this;
        }

        const VectorFunctionMetadata &build() const {
            return metadata_;
        }

    private:
        VectorFunctionMetadata metadata_;
    };
} // namespace kumo::pollux::exec
